package com.lengtouzai.databaseexp.view.workexperience;

import com.lengtouzai.databaseexp.entity.User;
import com.lengtouzai.databaseexp.entity.WorkExperience;
import com.lengtouzai.databaseexp.view.main.MainView;
import com.vaadin.flow.router.Route;
import io.jmix.core.security.CurrentAuthentication;
import io.jmix.flowui.model.CollectionLoader;
import io.jmix.flowui.view.*;
import org.springframework.beans.factory.annotation.Autowired;


@Route(value = "workExperiences", layout = MainView.class)
@ViewController("exp_WorkExperience.list")
@ViewDescriptor("work-experience-list-view.xml")
@LookupComponent("workExperiencesDataGrid")
@DialogMode(width = "64em")
public class WorkExperienceListView extends StandardListView<WorkExperience> {
    @Autowired
    private CurrentAuthentication currentAuthentication;
    @ViewComponent
    private CollectionLoader<WorkExperience> workExperiencesDl;

    @Subscribe
    public void onReady(final ReadyEvent event) {
        User current = (User) currentAuthentication.getUser();
        if (!current.getUsername().equals("admin")) {
            workExperiencesDl.setParameter("user", current);
        }
        workExperiencesDl.load();
    }
}